home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8304 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: gnu.gcc.help,comp.lang.c
  4. Subject: Re: Is this a compiler bug?
  5. Date: Sat, 02 Mar 96 23:45:09 GMT
  6. Organization: none
  7. Message-ID: <825810309snz@genesis.demon.co.uk>
  8. References: <3135FEDB.65AA@carbon.chem.nyu.edu> <4h991r$qon@segfault.monkeys.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4h991r$qon@segfault.monkeys.com>
  15.            rfg@monkeys.com "Ronald F. Guilmette" writes:
  16.  
  17. >I believe that in this case, the proper ANSI required behavior would be to
  18. >print:
  19. >
  20. >        foo = ''
  21. >
  22. >because there is some special clause in the C standard about tenative
  23. >declarations (e.g. your first declaration of the `foo' array) and their
  24. >handling at the end of a translation unit (i.e. `static_bug.c') in cases
  25. >where no non-tenative declaration/definition has been provided... and that
  26. >rule says that the compiler must act as if the data object in question
  27. >has an initializer of zero.  Thus, I believe that the compiler should
  28. >simulate the following definition at the end of the translation unit
  29. >unit `static_bug.c':
  30. >
  31. >        static const char foo[] = { 0 };
  32.  
  33. Except that 6.7.2 says:
  34.  
  35. "If the declaration of an identifier for an object is a tentative definition
  36.  and has internal linkage, the declared type shall not be an incomplete type"
  37.  
  38. Interestingly this is not a constraint so the compiler is not required
  39. to issue a diagnostic.
  40.  
  41. static const char foo[];
  42.  
  43. is a tentative definition with internal linkage and an incomplete type. So
  44. this results in undefined behaviour unless the type was completed by
  45. composition with an *earlier* declaration. The TC1 version of 6.1.2.6 is
  46. relevant:
  47.  
  48.   "For an identifier with internal or external linkage declared in a
  49.    scope in which a prior declaration of that identifier is visible, if
  50.    the prior declaration specifies internal or external linkage, the
  51.    type of the identifier at the latter declaration becomes the
  52.    composite type."
  53.  
  54. -- 
  55. -----------------------------------------
  56. Lawrence Kirby | fred@genesis.demon.co.uk
  57. Wilts, England | 70734.126@compuserve.com
  58. -----------------------------------------
  59.